package com.orkasgb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orkasgb.entity.OrkasgbUserEntity;
import com.orkasgb.mapper.OrkasgbUserMapper;
import com.orkasgb.service.IOrkasgbUserService;
import io.micrometer.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

import java.io.Serializable;
import java.util.List;

/**
 * 用户表(TOrkasgbUser)表服务实现类
 *
 * @version 1.0.0
 * @since 2024-11-08 14:54:39
 */
@Slf4j
@Service
public class OrkasgbUserServiceImpl extends ServiceImpl<OrkasgbUserMapper, OrkasgbUserEntity> implements IOrkasgbUserService {

    @Resource
    private OrkasgbUserMapper orkasgbUserMapper;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Override
    public OrkasgbUserEntity getOrkasgbUser(Serializable id) {
        return this.getBaseMapper().selectById(id);
    }

    /**
     * 通过条件查询多条数据
     *
     * @param orkasgbUserEntity 实体查询参数
     * @return 数据
     */
    @Override
    public List<OrkasgbUserEntity> getOrkasgbUserList(OrkasgbUserEntity orkasgbUserEntity) {
        LambdaQueryWrapper<OrkasgbUserEntity> queryWrapper = new LambdaQueryWrapper<>(OrkasgbUserEntity.class);
        if (StringUtils.isNotBlank(orkasgbUserEntity.getUserAccount())) {
            queryWrapper.eq(OrkasgbUserEntity::getUserAccount, orkasgbUserEntity.getUserAccount());
        }
        return this.getBaseMapper().selectList(queryWrapper);
    }

    /**
     * 通过条件查询多条数据(分页查询)
     *
     * @param orkasgbUserEntity 查询参数实体
     * @return 数据
     */
    @Override
    public IPage<OrkasgbUserEntity> getOrkasgbUserPageDataList(OrkasgbUserEntity orkasgbUserEntity) {
        QueryWrapper<OrkasgbUserEntity> queryWrapper = new QueryWrapper<>(OrkasgbUserEntity.class);
        IPage<OrkasgbUserEntity> page = new Page<>(orkasgbUserEntity.getCurrent(), orkasgbUserEntity.getPageSize());
        return this.page(page, queryWrapper);
    }

    /**
     * 新增数据
     *
     * @param orkasgbUserEntity 实体对象
     * @return 新增结果
     */
    @Override
    public int addOrkasgbUser(OrkasgbUserEntity orkasgbUserEntity) {
        return this.getBaseMapper().insert(orkasgbUserEntity);
    }

    /**
     * 修改数据
     *
     * @param orkasgbUserEntity 实体对象
     * @return 修改结果
     */
    @Override
    public int updateOrkasgbUser(OrkasgbUserEntity orkasgbUserEntity) {
        return this.getBaseMapper().updateById(orkasgbUserEntity);
    }

    /**
     * 修改或者新增数据
     *
     * @param orkasgbUserEntityList 实体对象
     * @return 操作结果
     */
    @Override
    public int addOrUpdateOrkasgbUser(List<OrkasgbUserEntity> orkasgbUserEntityList) {
        return orkasgbUserMapper.insertOrUpdateBatch(orkasgbUserEntityList);
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @Override
    public int deleteOrkasgbUserByIds(List<Long> idList) {
        return this.getBaseMapper().deleteByIds(idList);
    }
}

